<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>登录 | 音乐播放器</title>

  <link rel="stylesheet" href="css/bootstrap.min.css" />
  <script src="js/jquery-3.1.1.min.js"></script>

  <style>
    body {
  margin: 0;
  padding: 0;
  height: 100vh;
  background: url('/images/myImg.jpg') no-repeat center center fixed;
  background-size: cover;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e0e0e0;
}

    .login-box {
      width: 100%;
      max-width: 420px;
      padding: 40px;
      background: rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(16px);
      border-radius: 20px;
      border: 1px solid rgba(255, 255, 255, 0.1);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
      transition: all 0.3s ease;
    }

    .login-box h3 {
      text-align: center;
      margin-bottom: 30px;
      background: linear-gradient(90deg, #8a79ff, #a57aff);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: bold;
      font-size: 26px;
    }

    .form-group label {
      color: #ccc;
      font-weight: 500;
    }

    .form-control {
      background-color: rgba(255, 255, 255, 0.07);
      border: none;
      color: #fff;
      border-radius: 8px;
    }

    .form-control::placeholder {
      color: #aaa;
    }

    .form-control:focus {
      background-color: rgba(255, 255, 255, 0.12);
      box-shadow: 0 0 0 2px #6a5acd;
      border: none;
    }

    .btn-login {
      width: 100%;
      height: 45px;
      margin-top: 25px;
      background: linear-gradient(135deg, #6a5acd, #8e7dff);
      border: none;
      color: #fff;
      font-weight: bold;
      border-radius: 10px;
      transition: 0.3s ease;
    }

    .btn-login:hover {
      background: linear-gradient(135deg, #9b87ff, #bfa7ff);
      transform: scale(1.02);
      box-shadow: 0 0 15px rgba(138, 115, 255, 0.4);
    }

    .alert {
      margin-top: 20px;
      display: none;
      background-color: rgba(255, 0, 0, 0.1);
      border: 1px solid #ff4d4d;
      color: #ffcccc;
      border-radius: 6px;
    }

    .close {
      color: #fff;
      opacity: 0.8;
    }

    @media screen and (max-width: 480px) {
      .login-box {
        padding: 30px 20px;
      }
    }
  </style>
</head>
<body>
<div class="login-box">
  <h3>🎧 音乐服务器登录</h3>

  <div class="form-group">
    <label for="user">👤 用户名</label>
    <input type="text" class="form-control" id="user" placeholder="请输入用户名" />
  </div>

  <div class="form-group">
    <label for="password">🔒 密码</label>
    <input type="password" class="form-control" id="password" placeholder="请输入密码" />
  </div>

  <button id="submit" class="btn btn-login">🎵 登录</button>

  <div class="alert alert-danger" id="messageBox">
    <button type="button" class="close" data-dismiss="alert">
      <span>&times;</span>
    </button>
    <strong id="message">请输入用户名和密码！</strong>
  </div>

  <div class="text-center mt-3">
    <a href="register.html" class="btn btn-link text-decoration-none" style="color: #8a79ff;">还没有账号？立即注册</a>
  </div>
</div>

  <script>
    $(function () {
      $("#submit").click(function () {
        var username = $("#user").val().trim();
        var password = $("#password").val().trim();

        if (username === "" || password === "") {
          $("#message").text("请输入用户名和密码！");
          $("#messageBox").fadeIn();
          return;
        }

        $.ajax({
          url: "/user/login",
          type: "post",
          dataType: "json",
          data: {
            username: username,
            password: password
          },
          success: function (result) {
            if (result.status === 0) {
              alert("登录成功！");
              window.location.href = "list.html";
            } else {
              $("#message").text("账号或密码错误，请重试！");
              $("#messageBox").fadeIn();
              $("#user").val("");
              $("#password").val("");
            }
          },
          error: function () {
            $("#message").text("服务器连接失败，请稍后重试！");
            $("#messageBox").fadeIn();
          }
        });
      });
    });
  </script>
</body>
</html>
